#include "common.hpp"
#include "log.hpp"
#include"reactor.hpp"
#include"channel.hpp"
#include"listener.hpp"
#include"calculate.hpp"
int main(int argc, char *argv[])
{
   consolestrategy  ;
    if (argc != 2)
    {
        std::cerr << "please use: " << argv[0] << " port" << std::endl;
        return 1;
    }
  
     //业务层：
      unique_ptr<cal> upc=make_unique<cal>();
     //协议层：
          unique_ptr<protocol>upl=make_unique<protocol>([&upc](request &re)->response{
               return upc->excute(re);

          });
     

    
    //构建Reactor管理的服务器：
    shared_ptr<Connection> con=make_shared<Listener>(stoi(argv[1]));
    con->Setfunc([&](string &s)->string{
        cout<<"开始解码"<<endl;
        string send_strs;
        string ans;
        bool ok= upl->Decode(s,&ans);
        if(ok){ 
        //成功解码，是一个完成序列，拿到json串
        cout<<"成功解码"<<endl;
         string final=upl->Excute(ans);
         cout<<"执行完毕"<<endl;
       send_strs+=final;
        }
       return send_strs;


    });
    unique_ptr<Reactor> r=make_unique<Reactor>();
    r->Addconnection(con);
    r->loop();


}

